#include <bits/stdc++.h>
using namespace std;
struct card{
    char r, s;
    card(char r, char s):r(r), s(s){}
};


vector<stack<card> > S;
int canMove(int i){
    int p1 = i, p3 = i;
    for (int mov = 1; mov <= 3; ++mov) {
        if(mov==1){
            while(p1-1>=0 && S[p1-1].empty()) --p1;
            --p1;
        }

        while(p3-1>=0 && S[p3-1].empty()) --p3;
        --p3;
    }
    if(p3>=0){
        card c1 = S[i].top(), c2 = S[p3].top();
        if(c1.s == c2.s || c1.r == c2.r) return p3;
    }
    if(p1>=0){
        card c1 = S[i].top(), c2 = S[p1].top();
        if(c1.s == c2.s || c1.r == c2.r) return p1;
    }
    return -1;

}
void move(int i, int j){
    card c = S[i].top(); S[i].pop();
    S[j].push(c);
}
int main() {
    ios_base::sync_with_stdio(false);cin.tie(nullptr);
    string in;
    while(cin >> in && in!="#"){
        S.clear();
        card c(in[0], in[1]);
        stack<card> s1; s1.push(c);
        S.push_back(s1);
        for (int i = 1; i < 52; ++i) {
            cin >> in;
            card t(in[0], in[1]);
            stack<card> s2;
            s2.push(t);
            S.push_back(s2);
        }

        int p=1;
        while(p<52){
            if(S[p].empty()) {++p; continue;}
            int p1 = p, p2 = canMove(p1);
            bool change = p2 >= 0;
            while(p2>=0){
                move(p1, p2);
                p1 = p2;
                p2 = canMove(p1);
            }
            p = change? p1+1 : p+1;
        }


        int cnt = 0;
        for(auto &i:S) if(!i.empty()) ++cnt;
        string pile = cnt>1? "piles":"pile";

        cout << cnt << " " << pile << " remaining:";
        for(auto &i:S) if(!i.empty()){
            cout << " " << i.size();
        }
        cout << "\n";
    }
    return 0;
}